package org.example.sword2offer.primary;

/**
 * @author: lynn
 * @Descript: 判断是否为对称二叉树
 * @date: 2021/6/16 21:44
 * @version: 1.0
 */
public class Q18_1_IsMirrorTree {

    public static void main(String[] args) {

    }
    public Boolean judgeTree(TreeNode treeNode){ //判断是否为对称二叉树
        return treeNode==null? true: recureTree(treeNode.left,treeNode.right);
    }
    private static boolean recureTree(TreeNode leftNode,TreeNode rightNode){
        if (leftNode==null && rightNode==null) return true;
        if (leftNode==null || rightNode==null || leftNode.val!=rightNode.val) return false;
        return recureTree(leftNode,rightNode)&&recureTree(rightNode,leftNode);
    }
    private static class TreeNode{
        TreeNode left;
        TreeNode right;
        int val;
        TreeNode(int val){
            this.val=val;
        }
    }
}
